package com.fanyouzhao.ssm251.controller;

import com.fanyouzhao.ssm251.exception.BusinessException;
import com.fanyouzhao.ssm251.util.JsonResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author: fanyouzhao
 * @date: 16:58 2021/6/1
 */
@Controller
@ControllerAdvice
public class ExceptionController {

    @ExceptionHandler({Throwable.class})
    @ResponseBody
    public JsonResult throwableHandler(Exception e){
        JsonResult jsonResult = new JsonResult();
        if (e instanceof BusinessException){
            System.out.println("e = " + e);
            // 向前端返回消息
        }else {
            // 把系统异常记录日志
        }
        return jsonResult;
    }
}